import wepy from 'wepy'
import { api } from './config'
import { requestData } from './util'

export const getBanner = () => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.ad.list.url,
      method: api.ad.list.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const courseMainList = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.course.listSupreme.url,
      method: api.course.listSupreme.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params,
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const getBookshelf = () => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.bookshelf.url,
      method: api.user.bookshelf.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const categoryList = () => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.category.list.url,
      method: api.category.list.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
// export const categoryListPage = (params) => {
//   return new Promise((resolve, reject) => {
//     requestData({
//       url: api.category.pageList.url,
//       method: api.category.pageList.method,
//       header: {
//         Accept: 'application/json',
//         'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
//         token: wepy.getStorageSync('LOGIN')
//       },
//       data: params
//     }, function(data) {
//       resolve(data)
//     }, function(error) {
//       reject(error)
//     })
//   })
// }
export const courseListPage = (params,courseId) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.category.courseCategory.url + `/${courseId}/pageCourses`,
      method: api.category.courseCategory.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const getCourseDetail = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.course.courseInfo.url+`/content/${params}`,
      method: api.course.courseInfo.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const getCourseLesson = (courseId, lessonId) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.course.courseInfo.url+`/${courseId}/lesson/${lessonId}`,
      method: api.course.courseInfo.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const coursePayment = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.payment.url,
      method: api.user.payment.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}
export const getUserInfo = () => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.user.userInfo.url,
      method: api.user.userInfo.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      }
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

//建议邀请关系
export const createLakeUser = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.invite.invite.url,
      method: api.invite.invite.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}


//实时同步课程播放进度
export const lessonPlayProgress = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.course.lessonPlayProgress.url,
      method: api.course.lessonPlayProgress.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

//实时同步课程播放次数
export const lessonPlayCount = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.course.lessonPlayCount.url,
      method: api.course.lessonPlayCount.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

export const detailCount = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: 'https://shetest.tuoketech.com/lake/lake/incomeDetail/lakeIncomeDetailCount',
      method: 'get',
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

export const rewardList = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: 'https://shetest.tuoketech.com/lake/lake/incomeDetail/list',
      method: 'get',
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

export const accountInfo = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
       url: api.invite.accountInfo.url,
      method: api.invite.accountInfo.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}

export const record = (params) => {
  return new Promise((resolve, reject) => {
    requestData({
      url: api.invite.record.url,
      method: api.invite.record.method,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
        token: wepy.getStorageSync('LOGIN')
      },
      data: params
    }, function(data) {
      resolve(data)
    }, function(error) {
      reject(error)
    })
  })
}